package util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.*;

public abstract class SocketThread extends Thread {

	protected boolean connectionClosed = false;
	protected Socket socket;
	protected BufferedReader in;
	protected PrintWriter out;
	
	public SocketThread(Socket Socket) throws UnsupportedEncodingException, IOException{
		super();
		this.socket = Socket;
		
		in = new BufferedReader( new InputStreamReader( this.socket.getInputStream() , "UTF-8" ) );
		out = new PrintWriter( new OutputStreamWriter( this.socket.getOutputStream() , "UTF-8" ) , true );
	}
	
	public abstract void run();
	
	public void send(String str) {
		out.println(str);
		out.flush();
	}
	
	public void close() {
		try {
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public boolean isClosed() {
		return connectionClosed;
	}
}
